<template>
    <div class="listDiv pd20">
        <div class="searchDiv">
            <el-form class="searchLeft" ref="serform" :model="obj.req" label-position="top">
                <el-form-item class="mr20 mb10">
                    <span class="btn add" @click="add">添加规则</span>
                </el-form-item>
                <span class="btn search mb10 mr5" @click="obj.req.currentpage=1;init()">查询</span>
            </el-form>
        </div>
        <div class="table" id="tb">
            <ul class="head">
                <li class="liflex">文件文本</li>
                <li class="liflex">初始编号</li>
                <li class="liflex">最新编号</li>
                <li class="liflex">是否当前年</li>
                <li class="listate">是否默认</li>
                <li class="listate">状态</li>
                <li class="liaction">操作</li>
            </ul>
            <div class="body">
                <ul v-for="x in obj.ary" :key="x">
                    <li class="liflex flex-center">{{x.txt}}</li>
                    <li class="liflex flex-center">{{x.start}}</li>
                    <li class="liflex flex-center">{{x.cur}}</li>
                    <li class="liflex flex-center">{{ x.is_year==1?'是':'否' }}</li>
                    <li class="listate">
                        <el-switch v-model="x.is_default" :disabled="x.state==0" size="small" :validate-event="false" @change="setstate(x,'default')"
                            active-text="是" inactive-text="否"
                            :active-value="1" :inactive-value="0">
                        </el-switch>
                    </li>
                    <li class="listate">
                        <el-switch v-model="x.state" :disabled="x.is_default==1" size="small" :validate-event="false" @change="setstate(x,'setstate')"
                            active-text="正常" inactive-text="停用"
                            :active-value="1" :inactive-value="0">
                        </el-switch>
                    </li>
                    <li class="liaction">
                        <u @click.prevent="edit(x)" v-if="x.is_default!=1">编辑</u>
                        <DelConfirm @yesClick="del(x)" v-if="x.is_default!=1" />
                    </li>
                </ul>
            </div>
        </div>
    </div>
</template>

<script setup>
    import { reactive,getCurrentInstance,onActivated } from 'vue'
    import DelConfirm from '@/components/del_confirm.vue'
    let { proxy } = getCurrentInstance()

    let obj = reactive({
        ary:[],
        req:{}
    })

    onActivated(()=>{
        init()
    })

    let init = () => {
        proxy.$ajax({
            url: '/manager/ref/list',
            data: obj.req,
            bfLoading: true
        }).then(d => {
            if(d.success){
                obj.ary = d.msg.list
            }
        }).catch(() => { })
    }

    let add = () => {
        proxy.routerPushMixin("/refEdit",{})
    }
    let edit = x => {
        proxy.routerPushMixin("/refEdit",x)
    }

    let setstate = (x,type) => {
        proxy.$ajax({
            url: `/manager/ref/${type}`,
            data: { ref_id: x.ref_id },
            bfLoading: true
        }).then(da => {
            if(da.success){
                proxy.elMessageMixin(`成功`, 'success')
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }

    let del = x => {
        proxy.$ajax({
            url: '/manager/ref/delete',
            data: { ref_id: x.ref_id },
            bfLoading: true
        }).then(d => {
            if(d.success){
                proxy.elMessageMixin("删除成功", 'success')
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }
</script>

<style scoped>
</style>